package org.snaker.engine.springboot.rest;

import org.snaker.engine.SnakerEngine;
import org.snaker.engine.access.QueryFilter;
import org.snaker.engine.springboot.rest.vo.ProcessDefineRequest;
import org.snaker.engine.springboot.rest.vo.ProcessDefineUpdateRequest;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 流程定义
 */
@RestController
@RequestMapping("/process/define")
public class ProcessDefineController {

    @Resource
    private SnakerEngine snakerEngine;

    /**
     * 创建流程定义
     *
     * @param defineRequest 定义参数
     */
    public boolean createDefine(ProcessDefineRequest defineRequest) {
        snakerEngine.process().saveProcess(new org.snaker.engine.entity.Process());

        return Boolean.TRUE;
    }

    /**
     * 修改流程定义
     * @param updateRequest 修改参数
     */
    public void updateDefine(ProcessDefineUpdateRequest updateRequest) {
        snakerEngine.process().saveProcess(new org.snaker.engine.entity.Process());
    }

    /**
     * 删除流程定义
     * 会清楚所有相关数据
     * @param processDefineId 流程定义ID
     */
    public void deleteDefine(String processDefineId) {
        snakerEngine.process().cascadeRemove(processDefineId);
    }

    public List<org.snaker.engine.entity.Process> processes() {
        QueryFilter filter = new QueryFilter();
       return snakerEngine.process().getProcesss(filter);
    }
}
